package com.ztom.v2;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhangTao
 */
public class Code01TwoSum {

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            Integer other = map.getOrDefault(target - nums[i], -1);
            if (other != -1) {
                return new int[] {i, other};
            }
            map.put(nums[i], i);
        }
        return new int[] {-1, -1};
    }
}
